package love.yuanmengrobot.springmvcdemo2.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import love.yuanmengrobot.springmvcdemo2.mapper.LoginfoMapper;
import love.yuanmengrobot.springmvcdemo2.pojo.SysLoginfo;
import love.yuanmengrobot.springmvcdemo2.service.LoginfoService;
import love.yuanmengrobot.springmvcdemo2.utils.DataGridView;
import love.yuanmengrobot.springmvcdemo2.vo.LoginfoVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class LoginfoServiceImpl implements LoginfoService {
    @Resource
    LoginfoMapper loginfoMapper;
    @Override
    public void addLoginfo(SysLoginfo loginfo) {
        this.loginfoMapper.insertSelective(loginfo);
    }

    @Override
    public DataGridView queryAllLogininfo(LoginfoVo loginfoVo) {
        Page<SysLoginfo> page=PageHelper.startPage(loginfoVo.getPage(),loginfoVo.getLimit());
        List<SysLoginfo> list=this.loginfoMapper.queryAllLoginfo(loginfoVo);
        return new DataGridView(page.getTotal(),list);
    }

    @Override
    public void deleteLoginfo(Integer id) {
        this.loginfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void batchDeleteLoginfo(Integer[] ids) {
        for (Integer id : ids) {
            this.loginfoMapper.deleteByPrimaryKey(id);
        }
    }
}
